//
//  ZH_TopImageTableViewCell.m
//  WisdomStar
//
//  Created by zhangliwen on 2018/10/25.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_TopImageTableViewCell.h"
@interface ZH_TopImageTableViewCell()
@property (nonatomic,weak)UIView *bgView;
@property (nonatomic,weak)UIImageView *photoImage;
@property (nonatomic,weak)UILabel *titleLabel;
@property (nonatomic,weak)UILabel *contentLabel;
@property (nonatomic,weak)UIButton *leftButton;
@property (nonatomic,weak)UIButton *rightButton;
@end
@implementation ZH_TopImageTableViewCell

///创建
+(instancetype)cellWithTableView:(UITableView*)tableView
{
    static NSString *ID = @"ZH_TopImageTableViewCell";
    ZH_TopImageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell == nil){
        cell = [[ZH_TopImageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}
///初始化
-(void)initDefault
{
    [self unShowClickEffect];
//    self.bottomLongLineImage.hidden = NO;
}
- (void)loadSubviewConstraints{
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.contentView);
        make.height.mas_equalTo(FITSCALE(241));
        make.bottom.equalTo(self.contentView);
    }];
    [self.photoImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(64));
        make.centerX.equalTo(self.contentView);
        make.height.mas_equalTo(FITSCALE(55));
        make.width.mas_equalTo(FITSCALE(55));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(self.photoImage.mas_bottom).offset(FITSCALE(15));
    }];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(FITSCALE(7));
    }];
    [self.leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentLabel.mas_bottom).offset(FITSCALE(19));
        make.width.mas_equalTo(FITSCALE(64));
        make.height.mas_equalTo(FITSCALE(25));
        make.right.equalTo(self.contentView.mas_centerX).offset(FITSCALE(-15));
    }];
    [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentLabel.mas_bottom).offset(FITSCALE(19));
        make.width.mas_equalTo(FITSCALE(64));
        make.height.mas_equalTo(FITSCALE(25));
        make.left.equalTo(self.contentView.mas_centerX).offset(FITSCALE(15));
    }];
}
- (void)updaUI:(NSDictionary *)dic{
    if (dic) {
        [self.photoImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVER_TEST,dic[@"head"]]] placeholderImage:nil];
        self.titleLabel.text = dic[@"nickname"];
        self.contentLabel.text = dic[@"sign"];
        NSString *string = [NSString stringWithFormat:@"%@",dic[@"is_attention"]];
        if ([string isEqualToString:@"1"]) {
            [self.leftButton setTitle:@"已关注" forState:UIControlStateNormal];
        }
        else{
            [self.leftButton setTitle:@"+ 关注" forState:UIControlStateNormal];
        }
    }
}
- (void)button:(UIButton *)btn{
    if (self.onButtonClick) {
        self.onButtonClick(btn.tag);
    }
}
#pragma mark - getter,setter
- (UIView *)bgView{
    if (!_bgView) {
        UIView *view = [UIView createViewWithBackgroundColor:[UIColor colorWithHexString:@"#00C9AE"]];
        [self.contentView addSubview:_bgView = view];
    }
    return _bgView;
}
- (UIImageView *)photoImage{
    if (!_photoImage) {
        UIImageView *image = [UIImageView createImageViewWithName:@""];
        image.backgroundColor = [UIColor redColor];
        image.layer.cornerRadius= FITSCALE(27);
        image.layer.masksToBounds = YES;
        image.clipsToBounds = YES;
        [self.contentView addSubview:_photoImage = image];
    }
    return _photoImage;
}
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        UILabel *label = [UILabel createLabelWithText:@"机构名..." font:kFontSize_28];
        label.textColor = kFontColorWhite;
        [self.contentView addSubview:_titleLabel = label];
    }
    return _titleLabel;
}
- (UILabel *)contentLabel{
    if (!_contentLabel) {
        UILabel *label = [UILabel createLabelWithText:@"个性签名: 认真备课..." font:kFontSize_26];
        label.textColor = kFontColorWhite;
        [self.contentView addSubview:_contentLabel = label];
    }
    return _contentLabel;
}
- (UIButton *)leftButton{
    if (!_leftButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"+ 关注" target:self action:@selector(button:)];
        button.backgroundColor = [UIColor colorWithHexString:@"#CCEEEE"];
        [button setTitleColor:[UIColor colorWithHexString:@"#42E2CD"] forState:UIControlStateNormal];
        button.titleLabel.font = kFontSize_26;
        button.layer.cornerRadius = FITSCALE(12);
        button.layer.masksToBounds = YES;
        button.clipsToBounds = YES;
        button.tag = 1;
        [self.contentView addSubview:_leftButton = button];
    }
    return _leftButton;
}
- (UIButton *)rightButton{
    if (!_rightButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"预约" target:self action:@selector(button:)];
        button.backgroundColor = [UIColor colorWithHexString:@"#00C9AE"];
        [button setTitleColor:kFontColorWhite forState:UIControlStateNormal];
        button.titleLabel.font = kFontSize_26;
        button.layer.cornerRadius = FITSCALE(12);
        button.layer.borderWidth = FITSCALE(1);
        button.layer.borderColor = [UIColor colorWithHexString:@"#B5FFF5"].CGColor;
        button.layer.masksToBounds = YES;
        button.clipsToBounds = YES;
        button.tag = 2;
        [self.contentView addSubview:_rightButton = button];
    }
    return _rightButton;
}
@end
